package copyengine.network.roomStructure.subMediator
{
	import copyengine.network.roomStructure.CENetworkCommandNotification;
	import copyengine.network.roomStructure.data.CENetworkRoomMediatorWhiteBoard;
	import copyengine.network.roomStructure.executeLayer.CENetworkRoomExecuteHandleNotification;
	import copyengine.utils.debug.CELog;

	import org.puremvc.as3.interfaces.INotification;

	public final class CENetworkRoomSubSendReceiveDataMediator extends CENetworkRoomSubMediatorBasic
	{
		public function CENetworkRoomSubSendReceiveDataMediator(_whiteBoard:CENetworkRoomMediatorWhiteBoard)
		{
			super(_whiteBoard);
		}

		override public function listNotificationInterests():Array
		{
			return [
				CENetworkCommandNotification.RECEIVE_COMMAND_SEND_DATA_TO_OTHER,
				CENetworkRoomExecuteHandleNotification.SEND_RECEIVE_INCOMING_DATA,
				]
		}

		override public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case CENetworkCommandNotification.RECEIVE_COMMAND_SEND_DATA_TO_OTHER:
					sendForwardData(notification.getBody());
					break;
				case CENetworkRoomExecuteHandleNotification.SEND_RECEIVE_INCOMING_DATA:
					onReceiveIncomingData(notification.getBody()["command"],
										  notification.getBody()["commandArg"],
										  notification.getBody()["forwardData"]);
					break;
			}
		}

		//====================
		//==Incoming Data
		//====================

		private function onReceiveIncomingData(_command:uint, _commandArg:Object, _forwardData:Object):void
		{
			switch (_command)
			{
				case CENetworkCommandNotification.S_RESERVE_COMMAND_RECEIVE_TRANSPOND_DATA:
					onReceiveTranspondData(_forwardData);
					break;
			}
		}

		private function onReceiveTranspondData(_forwardData:Object):void
		{
			var ltc:String = _forwardData["LTC"];
			if (ltc == null)
			{
				CELog.err("CENetworkRoomSubSendReceiveDataMediator->onReceiveTranspondData not hava Level Two Command");
			}
			else
			{
				var arg:Object = _forwardData["arg"];
				sendNotification(ltc, arg);
			}
		}


	}
}
